<!DOCTYPE html>
<html>
<head>
    <title>user form</title>
    <#include "/header.html">
    <style>
        .layui-upload-img {
            max-height: 100px;
        }
        
    </style>
    <script type="text/javascript">
    function verify() {
    	var newpassword= document.getElementById("passwordnew").value;
    	if(newpassword==null||newpassword==""){
    		alert("请先输入新密码！");
    		return "";
    	}
    	var newpassword2= document.getElementById("password").value;
    	if(newpassword!=newpassword2){
    		alert("确认密码与新密码不同！");
    		return "";
    	}
    	
    }
    </script>
</head>
<body class="bg-white">

<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <input type="hidden" name="avatar" value="">
                <div class="layui-upload">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="uploadPreview" src="${request.contextPath}/statics/images/avatar.png">
                        <p id="uploadText"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" class="layui-input layui-disabled" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="输入昵称" value="" class="layui-input layui-disabled" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">修改登录密码</label>
            <div class="layui-input-block">
                <input type="password" name="passwordnew" id="passwordnew" lay-verify="required" lay-reqtext="登录密码不能为空" placeholder="输入登录密码" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">确认密码</label>
            <div class="layui-input-block">
                <input type="password" onblur="this.value=verify()" id="password" name="password" lay-verify="required" lay-reqtext="登录密码不能为空" placeholder="输入登录密码" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label required">修改提现密码</label>
            <div class="layui-input-block">
                <input type="password" name="withdrawalPasswordnew" lay-verify="required" lay-reqtext="提现密码不能为空" placeholder="输入提现密码" value="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">确认密码</label>
            <div class="layui-input-block">
                <input type="password" id="withdrawalPassword" name="withdrawalPassword" lay-verify="required" lay-reqtext="提现密码不能为空" placeholder="输入提现密码" value="" class="layui-input" autocomplete="off">
            </div>
        </div> -->
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use(['form'], function () {
        var form = layui.form,
            $ = layui.$;

        var _parent = parent;
        if (_parent.formDataId > 0) {
            $.ajax({
                type: "POST",
                url: serverUrl('user/info/' + _parent.formDataId),
                data: {},
                dataType: "json",
                success: function (result) {
                    if (result.code === 0) {
                        form.val('dataForm', result.info);
                        document.getElementById('password').value="";
                        //document.getElementById('withdrawalPassword').value="";
                        if (result.info.avatar != '') {
                            $('#uploadPreview').attr('src', result.info.avatar);
                        }
                    }
                }
            });
        }
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var params = data.field;
            params['id'] = _parent.formDataId
            submitFormData('user/pwd', params);
            return false;
        });

    });
</script>
</body>
</html>